#include<iostream>
#include<unistd.h>



//锁类
class Mutex
{
public:
    Mutex()
    {
        pthread_mutex_init(&_mutex,nullptr);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&_mutex);
    }
    void lock()
    {
        pthread_mutex_lock(&_mutex);
    }
    void unlock()
    {
        pthread_mutex_unlock(&_mutex);
    }
private:
    pthread_mutex_t _mutex;
};


class Lock_Guard
{
public:

    Lock_Guard(Mutex *_mutex)
        :_mutex(_mutex)
    {
        _mutex->lock();
        std::cout << "加锁成功..." << std::endl;
    }
    ~Lock_Guard()
    {
        _mutex->unlock();
        std::cout << "解锁成功..." << std::endl;
    }
private:
    Mutex*_mutex;
};

